@use 'sass:map';

@use './shared' as *;
@use './design' as *;

$carousel: () !default;
$carousel: map.merge(
  (
    handler-color: get-css-var('bg-color-base'),
    handler-bg-color: get-css-var('content-color-base'),
    handler-opacity: 50%,
    handler-opacity-hover: 80%,
    handler-opacity-disabled: 30%,
    handler-size: 40px,
    pointer-bg-color: get-css-var('content-color-secondary'),
    pointer-width: 16px,
    pointer-width-active: 24px,
    pointer-height: 3px,
    pointer-radius: get-css-var('radius-small'),
    pointer-opacity: 50%,
    pointer-opacity-hover: 80%,
    pointer-opacity-active: get-css-var('carousel-pointer-opacity-hover'),
    pointer-opacity-disabled: 30%
  ),
  $carousel
);

.#{$namespace}-carousel {
  &-vars {
    @include define-preset-values('carousel', $carousel);
  }

  @include basis;
  @include inherit-color;

  position: relative;
  display: inline-flex;
  flex-direction: column;
  width: 100%;
  user-select: none;

  &--vertical {
    flex-direction: row;
    width: auto;
    height: 100%;
  }

  &__list {
    overflow: hidden;
  }

  &__track {
    display: flex;
    width: 100%;
    height: 100%;
    transition: get-css-var('transition-transform');
  }

  &--vertical &__track {
    flex-direction: column;
  }

  &__item {
    position: relative;
    display: inline-flex;
    padding: 0 10px;
  }

  &--vertical &__item {
    padding: 10px 0;
  }

  $arrow-padding: 10px;

  &__arrow {
    &--inside,
    &--outside {
      position: relative;
      z-index: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      pointer-events: none;
      user-select: none;
    }

    &--inside {
      position: absolute;
      top: 0;
      bottom: 0;
      opacity: 0%;
      transition: get-css-var('transition-opacity');
    }

    &--prev {
      padding-inline-end: $arrow-padding;
    }

    &--inside#{&}--prev {
      inset-inline-start: 20px;
    }

    &--next {
      padding-inline-start: $arrow-padding;
    }

    &--inside#{&}--next {
      inset-inline-end: 20px;
    }

    &--inside#{&}--show {
      opacity: 100%;
    }
  }

  &--vertical &__arrow {
    &--prev {
      padding: 0;
      padding-bottom: $arrow-padding;
    }

    &--next {
      padding: 0;
      padding-top: $arrow-padding;
    }
  }

  &__handler {
    display: flex;
    align-items: center;
    justify-content: center;
    width: get-css-var('carousel-handler-size');
    height: get-css-var('carousel-handler-size');
    color: get-css-var('carousel-handler-color');
    pointer-events: auto;
    cursor: pointer;
    background-color: get-css-var('carousel-handler-bg-color');
    border-radius: 50%;
    opacity: get-css-var('carousel-handler-opacity');
    transition: get-css-var('transition-opacity');

    &:hover {
      opacity: get-css-var('carousel-handler-opacity-hover');
    }

    &--disabled {
      cursor: not-allowed;

      &,
      &:hover {
        opacity: get-css-var('carousel-handler-opacity-disabled');
      }
    }
  }

  &__arrow--inside &__handle-inner {
    opacity: 0%;

    &--show {
      opacity: 100%;
    }
  }

  // &:hover &__handle-inner {
  //   opacity: 1;
  // }

  &__pointers {
    &--inside,
    &--outside {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 40px;
      pointer-events: none;
    }

    &--none {
      display: none;
    }

    &--inside {
      position: absolute;
      bottom: 0;
      left: 0;
    }

    &--outside {
      padding: 16px;
    }
  }

  &--vertical &__pointers {
    &--inside,
    &--outside {
      flex-direction: column;
      width: 40px;
      height: 100%;
    }

    &--inside {
      right: 0;
      bottom: 0;
      left: auto;
    }
  }

  &__pointer {
    display: flex;
    padding: 3px;
    pointer-events: auto;
    cursor: pointer;

    &-inner {
      display: inline-block;
      width: get-css-var('carousel-pointer-width');
      height: get-css-var('carousel-pointer-height');
      margin: 1px 0 2px;
      background-color: get-css-var('carousel-pointer-bg-color');
      border-radius: get-css-var('carousel-pointer-radius');
      opacity: get-css-var('carousel-pointer-opacity');
      transition:
        width get-css-var('transition-base'),
        get-css-var('transition-opacity');
    }

    &:hover &-inner {
      opacity: get-css-var('carousel-pointer-opacity-hover');
    }

    &--active &-inner {
      width: get-css-var('carousel-pointer-width-active');
      opacity: get-css-var('carousel-pointer-opacity-active');
    }

    $inner: #{&}-inner;

    &--disabled {
      cursor: not-allowed;

      &,
      &:hover {
        #{$inner} {
          opacity: get-css-var('carousel-pointer-opacity-disabled');
        }
      }
    }

    &--disabled#{&}--active {
      #{$inner} {
        opacity: get-css-var('carousel-pointer-opacity-disabled');
      }
    }
  }

  &--vertical &__pointer {
    &-inner {
      width: get-css-var('carousel-pointer-height');
      height: get-css-var('carousel-pointer-width');
      margin: 0 2px 1px 0;
      transition:
        height get-css-var('transition-base'),
        get-css-var('transition-opacity');
    }

    &--active .#{$namespace}-carousel__pointer-inner {
      height: get-css-var('carousel-pointer-width-active');
    }
  }
}
